<template>
  <div class="shopcar-container">
    <div class="mui-card" v-for="(item,i) in shopCarList" :key="item.id">
      <div class="mui-card-content">
        <div class="mui-card-content-inner">
          <mt-switch></mt-switch>
          <img :src="item.thumb_path" alt />
          <div class="info">
            <h1>{{item.title}}</h1>
            <div>
              <span class="price">￥{{item.sell_price}}</span>
              <numberbox :initCount="$store.getters.getCountObj[item.id]" :goodsid="item.id"></numberbox>
              <a href="#" @click="removeShopCar(item.id,i)">删除</a>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="mui-card">
      <div class="mui-card-content">
        <div class="mui-card-content-inner jiesuan">
          <div class="left">
            <p>总计 ( 不计运费 )</p>
            <p>
              已勾选商品
              <span class="red">0</span>件,总价
              <span class="red">￥6</span>
            </p>
          </div>
          <mt-button type="danger">去结算</mt-button>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import numberbox from "../subcomponents/shopcar-nobox.vue";
export default {
  data() {
    return {
      shopCarList: []
    };
  },
  created() {
    this.getShopCar();
  },
  methods: {
    getShopCar() {
      let idArr = [];
      this.$store.state.cart.forEach(item => {
        idArr.push(item.id);
      });
      if (idArr.length <= 0) {
        return;
      }
      this.axios
        .get("api/goods/getshopcarlist/" + idArr.join(","))
        .then(response => {
          if (response.data.status === 0) {
            this.shopCarList = response.data.message;
          }
        });
    },
    removeShopCar(goodsid, i) {
      this.shopCarList.splice(i, 1);
      this.$store.commit("removeGoodsInfo", goodsid);
    }
  },
  components: {
    numberbox
  }
};
</script>
<style lang="scss">
.shopcar-container {
  background-color: #eee;
  overflow: hidden;
  .mui-card-content-inner {
    display: flex;
    img {
      width: 60px;
      height: 60px;
    }
    h1 {
      font-size: 13px;
    }
    .info {
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      .price {
        font-weight: bold;
        color: red;
      }
    }
    .mint-switch{
      z-index: 99;
    }
  }
  .jiesuan {
    display: flex;
    justify-content: space-between;
    align-items: center;
    .red {
      color: red;
      font-size: 16px;
      font-weight: bold;
    }
  }
}
</style>